<?php require_once("includes/initializeSession.php"); ?>
<?php
if (!isset($_SESSION['person_number'])) {
    header('Location: agentLogin.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>  
    <title>ר.א צ'ק אין - פתרונות ביטוח</title>
    <head>
<?php require_once("includes/cssAndJs.php"); ?>

                    <script type="text/javascript">
                        //style="vertical-align:top"

                        $(document).ready(function() {

                          


                                    $("#manuimList").jqGrid({
                                        url: "gridFunctions/manuimActions.php",
                                        direction: 'rtl',
                                        async: false,
                                        datatype: 'json',
                                        pager: '#manuimPager',
                                        colNames: ['מספר שורה', 'מספר מנוי', 'תאריך אסמכתא', 'מצב', 'סוכן', 'לקוח', 'מתאריך', 'עד תאריך', 'סוג רכב', 'קוד דגם', 'מס רישוי', 'שנת ייצור', 'סוג מנוי', 'מחיר מנוי', 'אמצעי תשלום', 'עמלת סוכן', 'ע"ח עמלת סוכן', 'סה"כ לתשלום', 'שולם?', 'אחרון', 'תאריך עמלה'],
                                        colModel: [
                                            {name: 'manuy_row', hidden: true, index: 'manuy_row', width: 60, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'manuy_number', index: 'manuy_number', width: 80, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'create_2', index: 'create_2', width: 100, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'state', index: 'state', width: 60, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'agent_person_number', index: 'agent_person_number', width: 60, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'person_number', index: 'person_number', width: 120, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'from_2', index: 'from_2', width: 110, editable: true, align: 'right'},
                                            {name: 'until', index: 'until', width: 110, editable: true, align: 'right'},
                                            {name: 'manufacturer', index: 'manufacturer', width: 70, editable: true, align: 'right'},
                                            {name: 'model', index: 'model', width: 70, editable: true, align: 'right'},
                                            {name: 'license_plate', index: 'license_plate', width: 80, editable: true, align: 'right'},
                                            {name: 'production_year', index: 'production_year', width: 60, editable: true, align: 'right'},
                                            {name: 'product_desc', index: 'product_desc', width: 80, editable: true, edittype: "select"},
                                            {name: 'product_price', editoptions: {readonly: "readonly"}, index: 'product_price', width: 80, editable: true, align: 'right'},
                                            {name: 'paymen_type', index: 'paymen_type', width: 70, editable: true, align: 'right'},
                                            {name: 'agent_commission', index: 'agent_commission', width: 70, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                                            {name: 'from_agent_commission', index: 'from_agent_commission', width: 70, editable: true, align: 'right', edittype: 'checkbox', formatter: "checkbox", editoptions: {value: "1:0"}},
                                            {name: 'total_payment', index: 'total_payment', width: 60, editable: true, align: 'right'},
                                            {name: 'shulam', index: 'shulam', width: 60, editable: true, align: 'right', edittype: 'checkbox', formatoptions: {disabled: true}, formatter: "checkbox", editoptions: {value: "1:0"}},
                                            {name: 'last', hidden: true, index: 'last', width: 60, editable: true, align: 'right', edittype: 'checkbox', formatter: "checkbox", editoptions: {value: "1:0"}},
                                            {name: 'agentAmlaDate', index: 'agentAmlaDate', width: 110, editable: true, align: 'right'}
                                            ],
                                        rowNum: 20,
                                        rowList: [5, 10, 20, 50],
                                        sortname: 'person_number',
                                        sortorder: "desc",
                                        mtype: "POST",
                                        //loadonce: true,
                                        postData: {oper: 'viewManuimPerAgentPerAmlaDateOfMtriaAgent'},
                                        viewrecords: true,
                                        imgpath: '../../Scripts/css/Aristo/images',
                                        //autowidth: true,
                                        height: "100%"
                                    }); // -- end of   $("#list").jqGrid({
                                        //----------------- end manuim jqgrid

                                    $("#manuimList").jqGrid('navGrid', '#manuimPager', {edit: false, add: false, del: false,refresh: true, search: false});
                                    $('#manuimList').jqGrid('filterToolbar', {searchOnEnter: true, enableClear: false,afterSearch: getIncomesAndAmlotPerMetriaAgent
                                    });



 //------------------------------------datepicker for manuim search
 
 
                                 
 
                                   var  checkInDateInManuimSearch = $($("[id=gs_from_2]")[0]);
                                       var     checkOutDateInManuimSearch = $($("[id=gs_until]")[0]);
                                       
                                       
                                            checkInDateInManuimSearch.datepicker({
                                                dateFormat: 'yy-mm-dd',
                                            });

                                            checkOutDateInManuimSearch.datepicker({
                                                dateFormat: 'yy-mm-dd',
                                            });
                                            checkInDateInManuimSearch.datepicker('setDate', new Date().add(-1).year());
                                            checkOutDateInManuimSearch.datepicker('setDate', new Date().add(1).year());
                                            
                                            
                                        

                                    //-----------------------------------
                                   getIncomesAndAmlotPerMetriaAgent();
                                    
                                    
                                });// -- end of  $(document).ready(function ()
                                  
                                function getSelectedCellManuim(str)
                                {
                                    var grid = jQuery('#manuimList');
                                    var sel_id = grid.jqGrid('getGridParam', 'selrow');
                                    var myCellData = grid.jqGrid('getCell', sel_id, str);
                                    return myCellData;
                                }


                                function getIncomesAndAmlotPerMetriaAgent()
                                {
                                        $.ajax({url: 'gridFunctions/manuimActions.php',
                                        data: {oper: 'getIncomesAndAmlotPerMetriaAgent', manuy_number:$($("[id=gs_manuy_number]")[0]).val(),
create_2:$($("[id=gs_create_2]")[0]).val(),
state:$($("[id=gs_state]")[0]).val(),
agent_person_number:$($("[id=gs_agent_person_number]")[0]).val(),
person_number:$($("[id=gs_person_number]")[0]).val(),
from_2:$($("[id=gs_from_2]")[0]).val(),
until:$($("[id=gs_until]")[0]).val(),
manufacturer:$($("[id=gs_manufacturer]")[0]).val(),
model:$($("[id=gs_model]")[0]).val(),
license_plate:$($("[id=gs_license_plate]")[0]).val(),
production_year:$($("[id=gs_production_year]")[0]).val(),
product_desc:$($("[id=gs_product_desc]")[0]).val(),
product_price:$($("[id=gs_product_price]")[0]).val(),
paymen_type:$($("[id=gs_paymen_type]")[0]).val(),
agent_commission:$($("[id=gs_agent_commission]")[0]).val(),
from_agent_commission:$($("[id=gs_from_agent_commission]")[0]).val(),
total_payment:$($("[id=gs_total_payment]")[0]).val(),
shulam:$($("[id=gs_shulam]")[0]).val(),
agentAmlaDate:$($("[id=gs_agentAmlaDate]")[0]).val()},
                                        type: 'post',
                                        success: function(output)
                                        {
                                            //       console.log("output " + output);
                                            //    firstDate=output;
                                            // console.log(output)
                                        
                                            var report = eval('(' + output + ')')[0];
                                          $('#headerIncomes').text("מספר מנויים : " + report.manuimNumber);
                                            
                                          report1 = eval('(' + output + ')')[1];
                                          $('#headerAmla').text("עמלה לסוכן מטריה : " + report1.metriaAmla);
                                    $('#headerAmlot').text("עמלות לתקופה : " + report1.metriaAmla * report.manuimNumber);
                                           // return output.responseText;

                                        }
                                        
                                    });	//end og ajax call
                                    //   console.log("firstDate " + firstDate);
                                    return true;
                             
                                }             //  end getIncomesAndAmlotPerAgent
                    
                                



                    </script>
                    </head>
                    <body dir="rtl"  style="padding:0px; margin:0px;">
                        <div id="main">
                            <?php include("header.php"); ?>
                            
                            <h1 id="headerIncomes"></h1> 
                            <h1 id="headerAmla"></h1> 
                            <h1 id="headerAmlot"></h1> 

                 
                           <h1>רשימת כל המנויים שתחת סוכן מטריה</h1>   
                            <div id="lc">
                                <table id="manuimList" class="scroll" cellpadding="0" cellspacing="0"></table>
                                <div id="manuimPager" class="scroll" style="text-align: center;"> </div>
                            </div>
                            </br>
                           


                            <?php include("footer.php"); ?>	
                        </div>

                    </body>
                    </html>